import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home')
  },
  {
    path: '/register',
    name: 'Register',
    component: ()=> import('@/views/auth/Register'),
    meta: { title: '注册' }
  },
  {
    path: '/login',
    name: 'Login',
    component: ()=> import('@/views/auth/Login'),
    meta: { title: '登录' }
  },
  {
    path: '/404',
    name: '404',
    component: ()=> import('@/views/error/404'),
    meta: { title: '404-NotFound' }
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  routes
})

export default router
